[xenstored] Fix error path when xc_map_foreign_range fails.
authorChristian Limpach <Christian.Limpach@xensource.com>
Fri, 2 Mar 2007 11:25:12 +0000 (11:25 +0000)
committerChristian Limpach <Christian.Limpach@xensource.com>
Fri, 2 Mar 2007 11:25:12 +0000 (11:25 +0000)
If xc_map_foreign_range fails, the new domain object is freed,
but it is not removed from the connection list.

Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
tools/xenstore/xenstored_domain.c

index 5249ef6d56e1b86d4c395212bfefc9ad22b5eeac..f59ec31d56a596f3110b72049fd5167d270543ef 100644 (file)
@@ -320,6 +320,7 @@ void do_introduce(struct connection *conn, struct buffered_data *in)
        unsigned long mfn;
        evtchn_port_t port;
        int rc;
+       struct xenstore_domain_interface *interface;
 
        if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) {
                send_error(conn, EINVAL);
@@ -344,19 +345,21 @@ void do_introduce(struct connection *conn, struct buffered_data *in)
        domain = find_domain_by_domid(domid);
 
        if (domain == NULL) {
-               /* Hang domain off "in" until we're finished. */
-               domain = new_domain(in, domid, port);
-               if (!domain) {
+               interface = xc_map_foreign_range(
+                       *xc_handle, domid,
+                       getpagesize(), PROT_READ|PROT_WRITE, mfn);
+               if (!interface) {
                        send_error(conn, errno);
                        return;
                }
-               domain->interface = xc_map_foreign_range(
-                       *xc_handle, domid,
-                       getpagesize(), PROT_READ|PROT_WRITE, mfn);
-               if (!domain->interface) {
+               /* Hang domain off "in" until we're finished. */
+               domain = new_domain(in, domid, port);
+               if (!domain) {
+                       munmap(interface, getpagesize());
                        send_error(conn, errno);
                        return;
                }
+               domain->interface = interface;
                domain->mfn = mfn;
 
                /* Now domain belongs to its connection. */